/*FieldAnimation.cpp
FieldAnimation Implementation
Zach Agudelo, Andi Cescolini, Sam Tarin

Handles the "motion" of the players
basically cylces each player through individual sets of frames
called by Field class
*/

#include "FieldAnimation.h"
 //initialize
FieldAnimation::FieldAnimation() {
    CurrentFrame    = 0;
    MaxFrames       = 0;
    FrameInc        = 1;
 
    FrameRate       = 100; //Milliseconds
    OldTime         = 0;
 
    Oscillate       = false;
}
 
void FieldAnimation::OnAnimate() {
 	 //used to control speed of animation
    if(OldTime + FrameRate > SDL_GetTicks()) {
        return;
    }
 
    OldTime = SDL_GetTicks();
 
    CurrentFrame += FrameInc;
 	 //cycle through frames (oscillate goes back and forth)
    if(Oscillate) {
        if(FrameInc > 0) {
            if(CurrentFrame >= MaxFrames) {
                FrameInc = -FrameInc;
            }
        }else{
            if(CurrentFrame <= 0) {
                FrameInc = -FrameInc;
            }
        }
	 //not oscillate goes back to start from end
    }else{
        if(CurrentFrame >= MaxFrames) {
            CurrentFrame = 0;
        }
    }
}
//simple get and set for outside control
void FieldAnimation::SetFrameRate(int Rate) {
    FrameRate = Rate;
}
 
void FieldAnimation::SetCurrentFrame(int Frame) {
    if(Frame < 0 || Frame >= MaxFrames) return;
 
    CurrentFrame = Frame;
}
 
int FieldAnimation::GetCurrentFrame() {
    return CurrentFrame;
}

